package com.wy17113.controller.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.wy17113.model.entity.ScoreRecord;
import com.wy17113.model.service.IJokService;
import com.wy17113.model.service.IUserService;

public class AjaxOperateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/xml; charset=GBK");
		PrintWriter out = response.getWriter();
		
		WebApplicationContext webContext = WebApplicationContextUtils
				.getRequiredWebApplicationContext(request.getSession()
						.getServletContext());
		
		IJokService joks = (IJokService) webContext.getBean("jokService");

		String id = request.getParameter("id");
		int flag = Integer.parseInt(request.getParameter("flag"));
		
		try {
			joks.updateJokDC(flag, id);
			int count = joks.getJokState(flag, id);
			
			String result = id + "_" + count;			
			out.print(result);
		} catch (SQLException e) {
			out.print("flase");
		}		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
}